package com.cool.collect.springcode.a07;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * @author xiemiao
 * @description
 * @date 2023/08/31
 */
@SpringBootApplication
public class A07Application {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(A07Application.class, args);
        context.close();
    }

    /**
     * 三种初始化方法
     * 1. @PostConstruct
     * 2. 实现InitializingBean接口的afterPropertiesSet()方法
     * 3. @Bean注解的initMethod方法指定
     *
     * @return
     */
    @Bean(initMethod = "init3")
    public Bean1 bean1() {
        return new Bean1();
    }

    /**
     * 三种销毁方法
     * 1.@PreDestroy注解
     * 2.实现DisposableBean接口的destroy()方法
     * 3.@Bean注解的destroyMethod方法指定
     *
     * @return
     */
    @Bean(destroyMethod = "destroy3")
    public Bean2 bean2() {
        return new Bean2();
    }

}
